<template>
	<div>
		<div :span="24" class="header">
			<img src="../../static/img/zc.jpg" style="width: 100%;"/>
		</div>
		<div class="main">
			<section class="content-container">
				<div class="tab-list clearfix">
					<div class="list-box">调查录入</div>
					<div class="list-box">填报记录</div>
					<div class="list-box">个人中心</div>
					<div class="list-box">退出</div>
				</div>
				<div class="contentbox">
					<transition name="fade" mode="out-in">
						<router-view></router-view>
					</transition>	
					
				</div>
			</section>
		</div>
	</div>
</template>

<script>
	import ComFunJS from'../common/js/util'
	import { requestinfo ,requestquit} from '../api/api';
	export default {
		data() {
			return {
				sysName:'',
				userType:"",
				activeName:"",
				collapsed:false,
				sysUserName: '',
				sysUserAvatar: '',
				activeIndex2:"",
				ID:"2",
				form: {
					name: '',
					region: '',
					date1: '',
					date2: '',
					delivery: false,
					type: [],
					resource: '',
					desc: ''
				},
				router:[],
				userinfo:{
					
				}
			}
		},
		computed:{
	      activeIndex(value){
	        return this.$route.path.replace('/','')
	      }
	    },
		methods: {
			onSubmit() {
				console.log('submit!');
			},
			handleopen() {
				//console.log('handleopen');
			},
			handleclose() {
				//console.log('handleclose');
			},
			handleselect: function (a, b) {
			},
			//退出登录
			logout: function () {
				var _this = this;
				this.$confirm('确认退出吗?', '提示', {
					//type: 'warning'
				}).then(() => {
					requestquit().then(res=>{
						localStorage.removeItem('user');
						_this.$router.push('/login');
					})					
				}).catch(() => {

				});

			},
			//折叠导航栏
			collapse:function(){
				this.collapsed=!this.collapsed;
			},
			showMenu(i,status){
				this.$refs.menuCollapsed.getElementsByClassName('submenu-hook-'+i)[0].style.display=status?'block':'none';
			},
			validate(){
				requestinfo().then(res=>{
					if(res.error!=undefined){
						this.$router.push({ path:'/login' });
					}else{
						this.$store.state.role=res.role;
						localStorage.setItem('user',res.salt);
						this.userinfo=res;
						this.getrouter();
						this.sysName=this.userinfo.realName;
						if(this.userinfo.role=='teacher'){
							this.userType='老师'
						}
						if(this.userinfo.role=='child'){
							this.userType='同学'
						}							
					}
				})
			},
			getrouter(){		
				var role=this.userinfo.role;
				
				var routers=[];
				$.each(this.$router.options.routes, function(i,value) {		
					$.each(value.meta.role.split(','), function(e,result) {
						if(result==role&&value.meta.home=='resource'){
							routers.push(value)
						}
					});
				});
				this.router=routers				
			}			
		},
		mounted() {	
			this.validate();		
		}
	}

</script>

<style scoped src='../../static/css/all.css'>
</style>